#ifndef __TIMERFD_H__
#define __TIMERFD_H__

#include <functional>
#include <iostream>

using std::function;
using std::bind;
using std::cout;
using std::endl;

class TimerFd
{
    using TimerFdCallback = function<void()>;
public:
    TimerFd(int initSec, int peridocSec, TimerFdCallback &&cb);
    ~TimerFd();

    void start();
    void stop();

    //handleRead中执行read操作
    void handleRead();

private:
    int createTimerFd();
    void setTimerFd(int initSec, int peridocSec);

private:
    int _timerfd;//TimerFd系统调用返回的文件描述符
    int _initSec;
    int _peridocSec;
    bool _isStarted;//标志TimerFd对象是否运行标志
    TimerFdCallback _cb;//执行的任务

};

#endif
